package com.woniu.common.utils.messageUtil;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;

import static com.aliyun.teautil.Common.toJSONString;

public class SentMessage {

    public static final String SIGN_NAME = "蜗牛智慧园区";
    public static final String TEMPLATE_CODE = "SMS_477340042";

    public static void startSent(String phoneNum, String code) throws Exception {
//该方法用于发送短信验证码


        Client client = ClientFactory.createClient();

        // 构造请求对象，请替换请求参数值
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(phoneNum)//手机号
                .setSignName(SIGN_NAME)//短信签名
                .setTemplateCode(TEMPLATE_CODE)//短信模版
//                .setTemplateParam("{\"name\":\"张三\",\"number\":\"1390000****\"}");
                .setTemplateParam("{\"code\":" + code + "}"); // TemplateParam为序列化后的JSON字符串

        // 获取响应对象
        SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);


        // 响应包含服务端响应的 body 和 headers
        System.out.println(toJSONString(sendSmsResponse));
    }
}
